import React from 'react'
import { Image, TouchableOpacity } from 'react-native'
import PropTypes from 'prop-types'

/**
 * 图片按钮
 *
 * @export
 * @class ImageButton
 * @extends {React.Component}
 */
export default class ImageButton extends React.Component {
  static propTypes = {
    source: PropTypes.number.isRequired, // 图片路径
    onPress: PropTypes.func, // 按钮点击事件1,
    activeOpacity: PropTypes.number, // 点击时透明度
    style: PropTypes.object, // 图片样式
    touchStyle: PropTypes.object // 按钮样式
  }

  static defaultProps = {
    activeOpacity: 0.8
  }

  render() {
    return (
      <TouchableOpacity
        activeOpacity={this.props.activeOpacity}
        style={this.props.touchStyle}
        onPress={this.props.onPress}
      >
        <Image source={this.props.source} style={this.props.style}/>
      </TouchableOpacity>
    )
  }
}
